<link rel="stylesheet" type="text/css" href="../stylesheet/style.css"/>
<?php
/*
* @author Nguyen Xuan Hong
* @copyright 2011
*/

require_once('../includes/forms.tbl.php');

if($_GET['mode'] == 'listforms')
{
	$pClsForms = new clsFormsTable();	
	if($pClsForms->avaibleSubmit()){
		$pClsForms->loadBuffer();
		$attachfile = upload_file("Upload/", 'videobrowser_attach', $pClsForms->value('attach'));
		if($attachfile != "")
		{
			$pClsForms->setvalue('attach', $attachfile);
		} 
		
		$pClsForms->insertDB();
		echo acpredirect();
		exit();
	}
	echo $pClsForms->createForm('Thêm mẫu đơn');
	
	require_once('../includes/templates.php');
	$table = new clsTable('lstforms',array(array("ID", "1"),array("Tiêu đề mẫu đơn", 0),array("Sửa", 1),array("Xóa", 1)));
	$list_forms = $pClsForms->listobj(10);
	foreach($list_forms as $forms){
		$html_remove =      '<a href="?page=forms&mode=deleteforms&id='.$forms->value('id').'">Xóa</a>';
		$html_edit = 	'<a href="?page=forms&mode=editforms&id='.$forms->value('id').'">Sửa</a>';	
		$table->addRow($forms->value('id'),array($forms->value('id'),$forms->value('title'), $html_edit,$html_remove));
	}
	echo $table->putHTML(true);
	exit();
}

if($_GET['mode'] == 'deleteforms'){		
	// Redefine insert
	$deleteid = sget('id');			
	$pClsForms = new clsFormsTable($deleteid);
	if(!$_POST['submit']){
		?>
        
	<center><div class="notification warning">
        <span></span>
        <p><strong>Warning!</strong> 
		<div class="text">Bạn có muốn xóa mẫu đơn này không</div> 
            <div class="btn"><form method='post'><input type='submit' name='submit' value = 'Xóa' /></form></div>
         </p>
	</div></center>
        <?
		exit();
	}
	delete_file($pClsForms->value('attach'));
	$pClsForms->removeDB('id', $deleteid);
       header("location:index.php?page=forms&mode=listforms");
	exit();
}

if($_GET['mode'] == 'editforms')
{
	$edit = (int)sget('id');
	$pClsForms = new clsFormsTable($deleteid);
	if($pClsForms->avaibleSubmit()){
		$pClsForms->loadBuffer();
		$attachfile = upload_file("Upload/", 'videobrowser_attach', $pClsForms->value('attach'));
		if($attachfile != "")
		{
			$pClsForms->setvalue('attach', $attachfile);
		} 
		$pClsForms->updateDB('id',$edit);
        echo acpredirect('page=forms&mode=listforms');
		exit();
	}
	$pClsForms->loadDB('id',$edit);
       echo $pClsForms->createForm('Sửa mẫu đơn');
	exit();
}
?> 
